<template>
    <el-form label-position="left" :model="passwordInfo" ref="password" :rules="rules" label-width="80px" size="mini" style="padding:20px">
        <el-form-item label="原密码" prop="oldpassword">
            <el-input type="password" v-model="passwordInfo.oldpassword" placeholder="请输入原密码"></el-input>
        </el-form-item>
        <el-form-item label="新密码" prop="password">
            <el-input type="password" v-model="passwordInfo.password" placeholder="注：请使用字母数字和下划线组合"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="rpassword">
            <el-input type="password" v-model="passwordInfo.rpassword" placeholder="请再次输入新密码"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button @click.native="close" >取消</el-button>
            <el-button type="success" @click.native="callSubmit" :loading="loading">确定</el-button>
        </el-form-item>
        </el-row>
        <!-- <input type="hidden" name="id" value="{{shop_userinfo.id}}" > -->
    </el-form>
</template>
<script>
import C from '#/src/common/common.js'
import AdminChangepas from '#/src/organization/adminChangepas.js'

export default {
    name: 'admin_changepas',
    data() {
        return {
            passwordInfo: {
                oldpassword: '',
                password: '',
                rpassword: ''
            },
            loading: false,
            initialConditions: {},
            rules: {
                oldpassword: [
                    { required: true, message: '旧密码不能为空', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '新密码不能为空', trigger: 'blur' },
                    { max: 13, message: '最多13个字符', trigger: 'change' }
                ],
                rpassword: [
                    { required: true, message: '请再次输入密码', trigger: 'blur' },
                    { max: 13, message: '最多13个字符', trigger: 'change' }
                ]
            }
        }
    },
    mounted: function() {},
    methods: {
        async callSubmit(index) {
            // 验证
            var myreg = /^[a-zA-Z0-9]\w{5,17}$/
            if (!myreg.test(this.password)) {
                this.$notify.error({
                    title: '温馨提示',
                    message: '密码不能为中文且长度在6-18之间'
                })
                return
            }
            if (this.password !== this.rpassword) {
                this.$notify.error({
                    title: '温馨提示',
                    message: '两次输入的密码不一致！'
                })
                return
            }
            this.loading = true
            let data = await AdminChangepas.changepas(this.passwordInfo)
            this.loading = false
            if (data) {
                if (data.errno === 0) {
                    this.$message({
                        message: data.data.info,
                        type: 'success'
                    })
                    this.passwordInfo = { ...this.initialConditions }
                } else {
                    this.$message.error(data.errmsg)
                }
            }
        },
        close() {
            C.closeBrowserWindow()
        }
    }
}
//  //重置表单
//  $('input[name="oldpassword"]').val('');
</script>